package com.initialize.core.security.handler;

import cn.hutool.json.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/1/9
 * Time: 10:42 下午
 * Description:
 */
@Component
public class BaseLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 1006);
        jsonObject.put("msg", "退出成功");

        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().print(jsonObject.toString());
    }
}